package com.hadluo.qq.client.ui;

import com.hadluo.qq.client.model.FriendListItem;
import com.hadluo.qq.client.model.UserInfo;

import javax.swing.*;
import java.awt.*;

public class ChatFrame extends JFrame {
    private ChatPanel chatPanel;

    public ChatFrame(FriendListItem friend, UserInfo currentUser) {
        // 设置窗口基本属性
        setTitle("与 " + friend.getNickname() + " 聊天中");
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setSize(800, 700);
        setLocationRelativeTo(null);

        // 创建聊天面板
        chatPanel = new ChatPanel(friend, currentUser);
        setContentPane(chatPanel);

        // 设置窗口图标
        try {
            setIconImage(new ImageIcon(getClass().getResource("/icons/chat.png")).getImage());
        } catch (Exception e) {
            // 如果图标加载失败，忽略错误
        }

        // 添加窗口关闭事件监听器
        addWindowListener(new java.awt.event.WindowAdapter() {
            @Override
            public void windowClosing(java.awt.event.WindowEvent windowEvent) {
                dispose();
            }
        });
    }
}